﻿Public Class LISTINRECEIPT
    Dim connect As CONDB = CONDB.NewConnection()
    Dim PROVIDER_Check As New PROVIDERSCLASS

    Private Sub LISTINRECEIPT_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        SelectDatagridMasbilling()

        DesignForm(Me)
        DesignGrid(MASBILLINGGrid)

        PROVIDER_Check.GETHOSEM(CInt(main.txtUserRequest.Text.Trim), Convert.ToString(Me.Tag))
    End Sub

    Private Sub SelectDatagridMasbilling()
        Dim objSelectDataMASBILLING As New MASBILLING
        Dim MASBILLING As DataTable
        MASBILLING = connect.GetTable(objSelectDataMASBILLING.SelectMasbilling_)
        MASBILLINGGrid.PrimaryGrid.DataSource = MASBILLING
    End Sub

    Private Sub cleardata()
        BNAME_THTxt.Text = ""
        BNAME_ENTxt.Text = ""
        BILLIDTxt.Text = ""
        masbillingstatuscheck.Checked = False
    End Sub

    Private Sub MASBILLINGGrid_CellClick(sender As Object, e As DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs) Handles MASBILLINGGrid.CellClick
        Dim grid As DevComponents.DotNetBar.SuperGrid.GridRow
        grid = e.GridPanel.ActiveRow
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัส").Value() IsNot DBNull.Value Then
            BILLIDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัส").Value()
        Else
            BILLIDTxt.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อลำดับใบเสร็จภาษาไทย").Value() IsNot DBNull.Value Then
            BNAME_THTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อลำดับใบเสร็จภาษาไทย").Value()
        Else
            BNAME_THTxt.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อลำดับใบเสร็จภาษาอังกฤษ").Value() IsNot DBNull.Value Then
            BNAME_ENTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อลำดับใบเสร็จภาษาอังกฤษ").Value()
        Else
            BNAME_ENTxt.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value() = True Then
            masbillingstatuscheck.Checked = True
        Else
            masbillingstatuscheck.Checked = False
        End If
        connect = CONDB.NewConnection()
        If e.GridCell.GridColumn.Name = "สถานะการเปิดใช้งาน" Then
            Try
                Dim Sql As String
                connect.BeginTrans()
                Sql = "UPDATE MASBILLING SET "
                If Convert.ToBoolean(CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value()) = True Then
                    Sql += "`STATUS` = 1 "
                Else
                    Sql += "`STATUS` = 0 "
                End If
                Sql += "WHERE `BILLID` = '" & BILLIDTxt.Text & "' ;"
                connect.ExecuteNonQuery(Sql)
                connect.CommitTrans()
            Catch ex As Exception
                connect.RollbackTrans()
                MsgBox(ex.ToString)
            End Try
        End If
        addMasbilling.Enabled = False
    End Sub

    Private Sub addMasbilling_Click(sender As Object, e As EventArgs) Handles addMasbilling.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PADD_ = True Then
                If BNAME_THTxt.Text.ToString.Length > 0 And BNAME_ENTxt.Text.ToString.Length > 0 Then
                    Dim objInsertData As New MASBILLING
                    objInsertData.BNAME_TH_ = BNAME_THTxt.Text
                    objInsertData.BNAME_EN_ = BNAME_ENTxt.Text
                    objInsertData.STATUS_ = masbillingstatuscheck.Checked
                    objInsertData.insertMasbillingData()

                    SelectDatagridMasbilling()

                    cleardata()
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน", MsgBoxStyle.Critical)
                End If
            Else
                MsgBox(PROVIDER_Check.PADDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub editMasbilling_Click(sender As Object, e As EventArgs) Handles editMasbilling.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PUPD_ = True Then
                If BILLIDTxt.Text.ToString.Length > 0 Then
                    Dim editStat As Integer
                    editStat = MsgBox("ท่านต้องการแก้ไขข้อมูลส่วนดังกล่าวใช่หรือไม่", MsgBoxStyle.OkCancel)
                    If editStat = 1 Then
                        Dim objeditData As New MASBILLING
                        objeditData.BILLID_ = BILLIDTxt.Text
                        objeditData.BNAME_TH_ = BNAME_THTxt.Text
                        objeditData.BNAME_EN_ = BNAME_ENTxt.Text
                        objeditData.STATUS_ = masbillingstatuscheck.Checked
                        objeditData.editMasbillingData()

                        SelectDatagridMasbilling()

                        cleardata()
                    End If
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน", MsgBoxStyle.Critical)
                End If
                addMasbilling.Enabled = True
            Else
                MsgBox(PROVIDER_Check.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub importExel_Click(sender As Object, e As EventArgs) Handles importExel.Click
        Dim nextform As New IMPORTEXCEL("masbilling")
        nextform.ShowDialog()
    End Sub

    Private Sub exportExcel_Click(sender As Object, e As EventArgs) Handles exportExcel.Click
        Dim nextform As New IMPORTEXCEL("masbilling")
        nextform.ShowDialog()
    End Sub
End Class